<?php
namespace Home\Controller;
use Common\Controller\AppframeController;
use Home\Service\WechatService;
// +----------------------------------------------------------------------
// | Date:2017年2月17日
// +----------------------------------------------------------------------
// | Author: EK_熊<1439527494@qq.com>
// +----------------------------------------------------------------------
// | Description: 此文件作用于****
// +----------------------------------------------------------------------
class PublicController extends AppframeController{
    
    public function login(){
        $jump = I('jumpurl') ? base64_decode(I('jumpurl')) : U('index/index');
        if (IS_POST){
            $accountService = D('Account','Service');
            $ret = $accountService->login(I('u_account'),I('u_password'),'sn,position_lvl_id,leader_id,dep_id,dep_name,join_date,wx_openid,is_attendance,privilege');

            if (!$ret) $this->error($accountService->getError());
            $userinfo = $accountService->userInfo();
            /*添加年假记录*/
       //     $remianDays = D('AnnualLeave')->create_annual($userinfo['sn'],$userinfo['join_date']);
            $remianDays = D('AnnualLeave')->update_login($userinfo['sn'],$userinfo['join_date']);
            $this->success('登录成功！',$jump);
            exit();
        }
        $this->assign('jumpurl',$jump);
        $this->display();
    }
    
    
    

    
    
    /**
     * 微信授权登录回调方法
     * 
     * date:2017年3月13日
     * author: EK_熊
     */
    public function callback(){
        if ($_GET['aucode']){
            $wechat = new WechatService();
            $wxuser= $wechat->user_info($_GET['aucode']);
            //更新到员工数据平台
            $accountService = D('Account','Service');
            $userInfo  = $userinfo = $accountService->userInfo();
            $accountService = $accountService->update_user($userInfo['id'],['wx_openid'=>$wxuser['openid']],'wx_openid');
            
            $this->redirect('index/index');
        }
    }
    
    
    public function logout(){
        session('user',null);
        cookie('user',null);
        $this->success('退出成功！',U('index/index'));
    }
    
    public function welcome(){
//         \Think\Log::write($message);
        echo '牵着我的手,你就不会迷路。';
    }
    
}